package com.example.controller;

import com.example.pojo.Emp;
import com.example.pojo.LoginInfo;
import com.example.pojo.Result;
import com.example.service.EmpService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {
    private static final Logger log = LoggerFactory.getLogger(EmpController.class);
    @Autowired
    private EmpService empService;
    // 员工登录
    @PostMapping
    public Result login(@RequestBody Emp emp) {
        log.info("员工登录:{}",emp);
        LoginInfo loginInfo= empService.login(emp);
        if(loginInfo!=null){
            return Result.success(loginInfo);
        }else {
            return Result.error("用户名或密码错误");
        }
    }
}
